import { buyStock, orderList, sellStock } from '../../api/Trade'

const Trade = {
  actions: {
    orderList ({ commit }, userid) {
      return new Promise((resolve, reject) => {
        orderList(userid).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    buyStock ({ commit }, TradeInfo) {
      return new Promise((resolve, reject) => {
        buyStock(TradeInfo.userid, TradeInfo.stockcode, TradeInfo.stockname, TradeInfo.cost, TradeInfo.number).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    sellStock ({ commit }, TradeInfo) {
      return new Promise((resolve, reject) => {
        sellStock(TradeInfo.userid, TradeInfo.stockcode, TradeInfo.stockname, TradeInfo.cost, TradeInfo.number).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}
export default Trade
